package cn.youyeku.zsxh.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.Toast;

import cn.youyeku.zsxh.AboutUs;
import cn.youyeku.zsxh.MainActivity;
import cn.youyeku.zsxh.bean.Help;
import cn.youyeku.zsxh.bean.Question_center;
import cn.youyeku.zsxh.bean.question_data;
import cn.youyeku.zsxh.common.Contanst;


import cn.youyeku.zsxh.bean.Question;

import cn.youyeku.zsxh.ui.practice.QuestionPracticeActivity;
import cn.youyeku.zsxh.ui.teacher.ActTeacher;
import cn.youyeku.zsxh.ui.teacher.GraphicQuestion;
import cn.youyeku.zsxh.ui.teacher.GraphicQuestionShowChat;
import cn.youyeku.zsxh.ui.teacher.QuestionPostActivity;

import cn.youyeku.zsxh.ui.home.FollowsActivity;
import cn.youyeku.zsxh.ui.home.LoginActivity;

import cn.youyeku.zsxh.ui.home.PrivateMessage;
import cn.youyeku.zsxh.ui.activity.SettingActivity;

import cn.youyeku.zsxh.ui.activity.tabAct.ActGoodsExchange;
import cn.youyeku.zsxh.ui.activity.tabAct.ActGoodsExchangeAccepted;
import cn.youyeku.zsxh.ui.activity.tabAct.ActGoodsExchangePost;
import cn.youyeku.zsxh.ui.activity.tabAct.ActMutualAccepted;
import cn.youyeku.zsxh.ui.activity.tabAct.ActMutualHelp;
import cn.youyeku.zsxh.ui.activity.tabAct.ActMutualHelpPost;
import cn.youyeku.zsxh.ui.home.MsgListActivity;
import cn.youyeku.zsxh.ui.home.RegisterActivity;
import cn.youyeku.zsxh.ui.home.UnActive;
import cn.youyeku.zsxh.ui.home.UserInfoActivity;
import cn.youyeku.zsxh.ui.home.UserProfile;
import cn.youyeku.zsxh.ui.teacher.QuestionTeacherList;
import cn.youyeku.zsxh.ui.teacher.UpdateQuestions;


/**
 * Created by youye on 17-3-25.
 */

//ccontrol activity intent

public class UIControl {


    /**
     * 点击返回监听事件
     *
     * @param activity activity
     * @return 点击事件 并销毁改activity
     */
    public static View.OnClickListener finish(final Activity activity) {
        return new View.OnClickListener() {
            public void onClick(View v) {
                activity.finish();
            }
        };
    }

    public static void toastMessage(Context cont, String msg) {
        Toast.makeText(cont, msg, Toast.LENGTH_SHORT).show();
    }

    public static void toastMessage(Context cont, String msg, int time) {
        Toast.makeText(cont, msg, time).show();
    }

    public static AlertDialog.Builder getDialog(Context context, String title, String message,
                                                String... buttonStrs) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(context);
        dialog.setCancelable(false);
        dialog.setTitle(title);
        dialog.setMessage(message);
        dialog.setPositiveButton(buttonStrs[0], new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });

        return dialog;
    }

    public static void showLogin(Context context) {
        //跳转时候  清除
        Intent intent = new Intent(context, LoginActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);

    }

    public static void showMain(Context context) {
        //跳转时候  清除
        Intent intent = new Intent(context, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);


    }

    public static void showFansFollowActivity(Context context, String title) {
        Intent intent = new Intent(context, FollowsActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("title", title);
        context.startActivity(intent);
    }


    public static void showPrivateMessage(Context context, String sender_id, String title) {
        Intent intent = new Intent(context, PrivateMessage.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("uid", sender_id);
        intent.putExtra("title", title);
        context.startActivity(intent);
    }

    public static void showMsgListActivity(Context context) {
        Intent intent = new Intent(context, MsgListActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public static void showSetting(Context context) {

        Intent intent = new Intent(context, SettingActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public static void showUserInfo(Context context, String uid) {
        Intent intent = new Intent(context, UserInfoActivity.class);
        //没必要出现在历史
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("bundle_uid", uid);
        context.startActivity(intent);
    }

    public static void showAboutOurs(Context context) {
        Intent intent = new Intent(context, AboutUs.class);
        //没必要出现在历史
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        intent.putExtra("code", Contanst.ABOUT_US);
        context.startActivity(intent);
    }


    public static void showActGoodsExchange(Context context, Question_center questioncenter) {

        Intent intent = new Intent(context, ActGoodsExchange.class);
        intent.putExtra("questioncenter", questioncenter);
        context.startActivity(intent);
    }

    public static void showActMutualHelp(Context context, Help help) {

        Intent intent = new Intent(context, ActMutualHelp.class);
        intent.putExtra("help", help);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }


    public static void showActGoodsExchangePost(Context context) {

        Intent intent = new Intent(context, ActGoodsExchangePost.class);

        context.startActivity(intent);
    }

    public static void showActMutualHelpPost(Context context) {

        Intent intent = new Intent(context, ActMutualHelpPost.class);

        context.startActivity(intent);
    }

    public static void showActMutualAccepted(Context context) {

        Intent intent = new Intent(context, ActMutualAccepted.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public static void showQuestionPostActivity(Context context) {

        Intent intent = new Intent(context, QuestionPostActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public static void showQuestionDoActivity(Context context, question_data data) {

        Intent intent = new Intent(context, QuestionPracticeActivity.class);


        intent.putExtra("data",data);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }


    public static void showQuestionTeacherList(Context context) {
        Intent intent = new Intent(context, QuestionTeacherList.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }


//    /**
//     * 清除app缓存
//     */
//    public static void clearAppCache(final Activity activity) {
//        final Handler handler = new Handler() {
//            public void handleMessage(Message msg) {
//                if (msg.what == 1) {
//                    toastMessage(activity, "缓存清除成功");
//                } else {
//                    toastMessage(activity, "缓存清除失败");
//                }
//            }
//        };
//        new Thread() {
//            public void run() {
//                Message msg = new Message();
//                try {
//                    ((app) activity.getApplication()).clearAppCache();
//                    msg.what = 1;
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    msg.what = -1;
//                }
//                handler.sendMessage(msg);
//            }
//        }.start();
//    }

    /**
     * 打开浏览器
     *
     * @param context
     * @param url
     */
    public static void openBrowser(Context context, String url) {
        try {
            Uri uri = Uri.parse(url);
            Intent it = new Intent(Intent.ACTION_VIEW, uri);
            context.startActivity(it);
        } catch (Exception e) {
            e.printStackTrace();
            toastMessage(context, "无法浏览此网页", 500);
        }
    }

    public static void showUserProfile(Context context) {

        Intent intent = new Intent(context, UserProfile.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public static void showRegisterActivity(Context context) {
        Intent intent = new Intent(context, RegisterActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public static void showUnActiveActivity(Context context) {
        Intent intent = new Intent(context, UnActive.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public static void showActGoodsExchangeAccepted(Context context) {
        Intent intent = new Intent(context, ActGoodsExchangeAccepted.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);

    }

    public static void showUpdateQuestion(Context context, question_data data) {
        Intent intent = new Intent(context, UpdateQuestions.class);
        intent.putExtra("data", data);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public static void showGraphicQuestion(Context context, question_data data) {
        Intent intent = new Intent(context, GraphicQuestion.class);
        intent.putExtra("data", data);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public static void showTeacherMain(Context context) {
        Intent intent = new Intent(context, ActTeacher.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public static void showGraphicQuestionChat(Context context, Question data) {
        Intent intent = new Intent(context, GraphicQuestionShowChat.class);
        intent.putExtra("data", data);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);

    }


//    /**
//     * 显示分享操作
//     *
//     * @param context
//     * @param shareContent
//     * @param shareImage
//     */
//    public static void showShareOption(Activity context, String title,
//                                       String url, String shareContent, Bitmap shareImage) {
//        UMImage mUMImgBitmap = new UMImage(context, shareImage);
//        // 首先在您的Activity中添加如下成员变量
//        final UMSocialService mController = UMServiceFactory
//                .getUMSocialService("com.umeng.share");
//
//        // appID是你在微信开发平台注册应用的AppID, 这里需要替换成你注册的AppID
//        String appID = "wx850b854f6aad6764";
//        // 添加微信平台
//        UMWXHandler wxHandler = new UMWXHandler(context, appID);
//        wxHandler.addToSocialSDK();
//        // 设置分享到微信的内容
//        WeiXinShareContent weixinContent = new WeiXinShareContent(mUMImgBitmap);
//        weixinContent.setShareContent(shareContent);
//        weixinContent.setTitle(title);
//        weixinContent.setTargetUrl(url);
//        weixinContent.setShareImage(mUMImgBitmap);
//        wxHandler.mShareMedia = weixinContent;
//        mController.setShareMedia(weixinContent);
//
//        // 支持微信朋友圈
//        UMWXHandler wxCircleHandler = new UMWXHandler(context, appID);
//        // 设置朋友圈分享的内容
//        CircleShareContent circleMedia = new CircleShareContent();
//        circleMedia.setShareContent(shareContent);
//        circleMedia.setShareImage(mUMImgBitmap);
//        circleMedia.setTargetUrl(url);
//        circleMedia.setTitle(title);
//        wxCircleHandler.mShareMedia = circleMedia;
//        mController.setShareMedia(circleMedia);
//        wxCircleHandler.setToCircle(true);
//        wxCircleHandler.addToSocialSDK();
//
//        // 参数1为当前Activity，参数2为开发者在QQ互联申请的APP ID，参数3为开发者在QQ互联申请的APP kEY.
//        UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(context, "1101982202",
//                "GJxJGse5cu9iH4NM");
//        QQShareContent qqShareContent = new QQShareContent();
//        qqShareContent.setTitle(title);
//        qqShareContent.setShareContent(shareContent);
//        qqShareContent.setShareImage(mUMImgBitmap);
//        qqShareContent.setTargetUrl(url);
//        qqSsoHandler.mShareMedia = mUMImgBitmap;
//        mController.setShareMedia(qqShareContent);
//        qqSsoHandler.addToSocialSDK();
//
//        SinaSsoHandler sinaSsoHandler = new SinaSsoHandler();
//        SinaShareContent sinaShareContent = new SinaShareContent();
//        String form = "  分享自GitOSC移动客户端，好项目尽在https://git.oschina.net";
//        sinaShareContent.setShareContent(shareContent + " " + url + form);
//        sinaShareContent.setTargetUrl(url);
//        sinaShareContent.setShareImage(mUMImgBitmap);
//        sinaShareContent.setTitle(title);
//        mController.setShareMedia(sinaShareContent);
//        mController.getConfig().setSsoHandler(sinaSsoHandler);
//        // 移除人人分享操作
//        mController.getConfig().removePlatform(SHARE_MEDIA.RENREN,
//                SHARE_MEDIA.DOUBAN, SHARE_MEDIA.TENCENT);
//
//        mController.openShare(context, false);
//    }
//


}
